<template>
  <el-dialog
    :title="!dataForm.id ? $t('handle.add') : $t('handle.update')"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :disabled="formDisabled" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
      <el-row>
        <el-col :span="12">
          <el-form-item label="身份证姓名" prop="name" label-width="85px">
            <el-input v-model="dataForm.name" placeholder="身份证姓名"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
        <el-form-item label="身份证号" prop="idNumber" label-width="85px">
          <el-input v-model="dataForm.idNumber" placeholder="身份证号"></el-input>
        </el-form-item>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="12">
        <el-form-item label="身份证照片" prop="idPhoto" label-width="85px">
          <img :src="completionImgPath(dataForm.idPhoto)" @click="showImg('身份证照片', completionImgPath(dataForm.idPhoto))" style="max-height: 50px;max-width: 130px; cursor:pointer;">
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="人像照片" prop="portraitPhoto" label-width="85px">
          <img :src="completionImgPath(dataForm.portraitPhoto)" @click="showImg('人像照片', completionImgPath(dataForm.portraitPhoto))" style="max-height: 50px;max-width: 130px; cursor:pointer;">
        </el-form-item>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="12">
        <el-form-item label="民族" prop="nation" label-width="85px">
          <el-input v-model="dataForm.nation" placeholder="民族"></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item :label="$t('form.sex')" prop="sex" label-width="85px">
          <el-input v-model="dataForm.sex" placeholder="性别"></el-input>
        </el-form-item>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="12">
        <el-form-item label="住址" prop="address" label-width="85px">
          <el-input v-model="dataForm.address" placeholder="住址"></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="签发机关" prop="police" label-width="85px">
          <el-input v-model="dataForm.police" placeholder="签发机关"></el-input>
        </el-form-item>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="12">
        <el-form-item label="签发日期" prop="userlifeb" label-width="85px">
          <el-input v-model="dataForm.userlifeb" placeholder="签发日期"></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="失效日期" prop="userlifee" label-width="85px">
          <el-input v-model="dataForm.userlifee" placeholder="失效日期"></el-input>
        </el-form-item>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="12">
        <el-form-item :label="$t('form.birthDate')" prop="birthday" label-width="85px">
          <el-input v-model="dataForm.birthday" placeholder="出生日期"></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="比对阀值" prop="setThreshold" label-width="85px">
          <el-input v-model="dataForm.setThreshold" placeholder="比对阀值"></el-input>
        </el-form-item>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="12">
        <el-form-item label="比对分数" prop="comparisonThreshold" label-width="85px">
          <el-input v-model="dataForm.comparisonThreshold" placeholder="人证合一接口返回的比对值"></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="比对结果" prop="comparisonResult" label-width="85px">
          <el-select style="width: 100%;" v-model="dataForm.comparisonResult" filterable placeholder="比对结果">
              <el-option v-for="item in dicts" :key="item.value" :label="item.label" :value="item.value">
              </el-option>
            </el-select>
          <!-- <el-input v-model="dataForm.comparisonResult" placeholder="比对结果"></el-input> -->
        </el-form-item>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="12">
        <el-form-item label="创建时间" prop="createDate" label-width="85px">
          <el-input v-model="dataForm.createDate" placeholder="创建时间"></el-input>
        </el-form-item>
      </el-col>
    </el-row>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">{{ $t('handle.cancel') }}</el-button>
      <el-button v-if="!formDisabled" type="primary" @click="dataFormSubmit()">{{ $t('handle.confirm') }}</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        formDisabled: false,
        dicts: [],
        dataForm: {
          id: 0,
          name: '',
          idPhoto: '',
          sex: '',
          nation: '',
          idNumber: '',
          birthday: '',
          address: '',
          police: '',
          userlifeb: '',
          userlifee: '',
          portraitPhoto: '',
          setThreshold: '',
          comparisonThreshold: '',
          comparisonResult: '',
          createBy: '',
          createDate: '',
          updateBy: '',
          updateDate: '',
          delFlag: ''
        },
        dataRule: {
/*           name: [
            { required: true, message: '身份证姓名不能为空', trigger: 'blur' }
          ],
          idPhoto: [
            { required: true, message: '身份证照片不能为空', trigger: 'blur' }
          ],
          sex: [
            { required: true, message: '性别：男，女，未知；不能为空', trigger: 'blur' }
          ],
          nation: [
            { required: true, message: '民族：不能为空', trigger: 'blur' }
          ],
          idNumber: [
            { required: true, message: '身份证号不能为空', trigger: 'blur' }
          ],
          birthday: [
            { required: true, message: '出生日期不能为空', trigger: 'blur' }
          ],
          portraitPhoto: [
            { required: true, message: '人像照片，现场拍照照片（用于跟身份证照片比对的照片）不能为空', trigger: 'blur' }
          ],
          setThreshold: [
            { required: true, message: '设置的比对阀值不能为空', trigger: 'blur' }
          ],
          comparisonThreshold: [
            { required: true, message: '人证合一接口返回的比对值不能为空', trigger: 'blur' }
          ],
          comparisonResult: [
            { required: true, message: '人证合一比对结果不能为空', trigger: 'blur' }
          ],
          createBy: [
            { required: true, message: '创建人id不能为空', trigger: 'blur' }
          ],
          createDate: [
            { required: true, message: '创建时间不能为空', trigger: 'blur' }
          ],
          updateBy: [
            { required: true, message: '最后更新人id不能为空', trigger: 'blur' }
          ],
          updateDate: [
            { required: true, message: '最后更新时间不能为空', trigger: 'blur' }
          ],
          delFlag: [
            { required: true, message: '删除标识：1-未删，2-逻辑删除；关联码表不能为空', trigger: 'blur' }
          ] */
        }
      }
    },
    computed: {
      completionImgPath() {
        return function(path){
          return this.imgUrlHost + path;
      }
    }
    },
    methods: {
      init (id, formDisabled, dict) {
        this.dicts = dict
        this.dataForm.id = id || 0
        this.visible = true,
        this.formDisabled = formDisabled,
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: `/dg-ic/ic/combination-witness-testimony/info/${this.dataForm.id}`,
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.name = data.data.name
                this.dataForm.idPhoto = data.data.idPhoto
                this.dataForm.sex = data.data.sex
                this.dataForm.nation = data.data.nation
                this.dataForm.idNumber = data.data.idNumber
                this.dataForm.birthday = data.data.birthday
                this.dataForm.address = data.data.address
                this.dataForm.police = data.data.police
                this.dataForm.userlifeb = data.data.userlifeb
                this.dataForm.userlifee = data.data.userlifee
                this.dataForm.portraitPhoto = data.data.portraitPhoto
                this.dataForm.setThreshold = data.data.setThreshold
                this.dataForm.comparisonThreshold = data.data.comparisonThreshold
                this.dataForm.comparisonResult = data.data.comparisonResult
                this.dataForm.createBy = data.data.createBy
                this.dataForm.createDate = data.data.createDate
                this.dataForm.updateBy = data.data.updateBy
                this.dataForm.updateDate = data.data.updateDate
                this.dataForm.delFlag = data.data.delFlag
              }
            })
          }
        })
      },
      showImg(title,path) {
        this.$msgbox({
          title: title,
          message: "<img src='"+path+"'style='max-height: 300px;max-width: 300px'>",
          dangerouslyUseHTMLString: true,
          showCancelButton: false,
          showConfirmButton: false,
          center: true
        }).then(() =>{

        }).catch(() => {

        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/ic/iccombinationwitnesstestimony/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'name': this.dataForm.name,
                'idPhoto': this.dataForm.idPhoto,
                'sex': this.dataForm.sex,
                'nation': this.dataForm.nation,
                'idNumber': this.dataForm.idNumber,
                'birthday': this.dataForm.birthday,
                'portraitPhoto': this.dataForm.portraitPhoto,
                'setThreshold': this.dataForm.setThreshold,
                'comparisonThreshold': this.dataForm.comparisonThreshold,
                'comparisonResult': this.dataForm.comparisonResult,
                'createBy': this.dataForm.createBy,
                'createDate': this.dataForm.createDate,
                'updateBy': this.dataForm.updateBy,
                'updateDate': this.dataForm.updateDate,
                'delFlag': this.dataForm.delFlag
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>

<style scoped>

</style>

